package com.inspectortime.webapp.inspector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.inspectortime.domain.Inspector;
import com.inspectortime.repository.Repository;

/**
 * Simple controller that loads an inspector and places it in the view
 * 
 * @author bones
 *
 */
public class ViewInspectorController extends AbstractController {
	
	private static Log log = LogFactory.getLog(ViewInspectorController.class);
	
	private Repository repository;
	private String returnView;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String inspectorId = request.getParameter("inspectorId"); 
		Inspector inspector = repository.loadInspector(inspectorId);
		
		ModelAndView mv = new ModelAndView(getReturnView());
		mv.addObject("inspector", inspector);
		return mv;
		
		
	}
	
	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	public String getReturnView() {
		return returnView;
	}

	public void setReturnView(String returnView) {
		this.returnView = returnView;
	}

	
	
	

}
